﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using KPIReport.Library.DomainObject.Administration.UserManagement;
using KPIReport.Library.DataAccess.Administration.UserManagement;
using System.Configuration;
using KPIReport.Web.Support;

namespace KPIReport.Web.Forms.Administration.UserManagement
{
    public partial class changeAfterLoginform : BasePage
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!IsPostBack)
            {
                txtUserName.Text = base.UserLoggedIn;

                //GetPrivilege();
            }

        }

        private void GetPrivilege()
        {
            Membership membership = new Membership(ConfigurationManager.ConnectionStrings["KPIReportConn"].ConnectionString);

            List<recAccessRights.AccessRights> accessRights = membership.GetAccessRights(base.UserID, base.MenuID);
            
            if (hfIsForgotPassword.ToString() != "")
                {
                    accessRights.Add(recAccessRights.AccessRights.Edit);
                }  
            accessRights.ForEach(delegate(recAccessRights.AccessRights access)
            {
                         
                switch (access)
                {
                    case (recAccessRights.AccessRights.View):
                        ClientScript.RegisterStartupScript(typeof(Page), "view", "$('#btnSave').button('disable');", true);
                        break;
                    case (recAccessRights.AccessRights.Edit):
                        ClientScript.RegisterStartupScript(typeof(Page), "edit", "$('#btnSave').button('enable');", true);
                        break;
                    case (recAccessRights.AccessRights.NoAccess):
                            var url = Helper.GetAppVirtualPath(Page);
                            ClientScript.RegisterStartupScript(typeof(Page), "noAccess", "alert('Anda tidak mempunyai hak akses ke halaman ini!'); window.location = '" + url + "'", true);

                        break;
                }
            });

        }

    }

}